<?php
/*
Plugin Name: Megatop
Plugin URI: http://vmrf.ru
Description: Show mega top news
Author: vmrf.ru
Version: 1.0
Author URI: http://vmrf.ru
 */

namespace AY\Widget;

class Megatop extends \AY\Widget\AWidget
{
    protected $widgetName = 'Megatop';
    protected $widgetOptions = array(
		'classname'	=> 'megatop-ay',
		'description' 	=> 'widget show megtop news'
		);		
    //protected $countPost = 10;
    protected $category = 3; //ay()->region()->getRegionCategory();
    function widget( $args, $instance ) {
        $resentPost = wp_get_recent_posts(5);//array('numberposts'=>$instance['count'],'category'=>$this->category));
?>

<script src='/wp-includes/js/jquery/mbScrollable.js'></script>
<script>
$(function(){
       $("#myScroll").mbScrollable({
        width:650,
        elementsInPage:1,
        elementMargin:2,
        shadow:"#999 2px 2px 2px",
        height:"auto",
        controls:"#controls",
        slideTimer:600,
        autoscroll:true,
        scrollTimer:4000
      });
});
</script>
 <div id="myScroll">
<?php
        foreach ($resentPost as $post) {
            echo ' <div class="scrollEl" style="background-color:#009999"><a href="' . get_permalink($post["ID"]) . '" title="' . $post["post_title"] . '">' . $post["post_title"] . '</a> ' . $post['post_excerpt'] . '</div>';
        }
echo '</div>';
	?>
  <div id="controls">
    <div class="pageIndex"></div>
  </div>
<?php
}
	
	function form( $instance ) {
	$count = esc_attr($instance['count']);?>
<label for="<?php echo $this->get_field_id('count');?>">Количество новостей</label>
	<input class="widefat" id="<?php echo $this->get_field_id('count');?>" name="<?php echo $this->get_field_name('count'); ?>" type="text" value="<?php echo $count;?>">
	<?php }
	
	function update($new_instance, $old_instance) {
	return $new_instance;
	}
	
}
